home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_349 / med / source / med200src.zoo / med-ed.c < prev    next >
C/C++ Source or Header  |  1990-04-08  |  7KB  |  216 lines

  1. /* MED-plr.c by Teijo Kinnunen 1989, 1990 */
  2. /* Sisältää: editoinnin */
  3. #include "med.h"
  4.  
  5. UWORD near periodit[] = { 856,808,762,720,678,640,604,570,538,508,480,453,
  6.               428,404,381,360,339,320,302,285,269,254,240,226,
  7.               214,202,190,180,170,160,151,143,135,127,120,113,
  8.               214,202,190,180,170,160,151,143,135,127,120,113,
  9.               214,202,190,180,170,160,151,143,135,127,120,113,
  10.               214,202,190,180,170,160,151,143,135,127,120,113 };
  11. UBYTE firstdisptrk = 0,counter = 0;
  12. extern void __asm PaivitaNaytto(register __d0 UWORD);
  13. struct Library *ciaaresource;
  14. extern struct Gadget far gadget6[];
  15. extern struct Kappale far tamakappale;
  16. extern struct RastPort *wrp;
  17. extern UWORD volatile soittorivi,soittolohko,soittotila;
  18. extern UWORD kursorix,currtrk,soittimennum,lohkoja,currpos;
  19. extern struct Lohko far *lohko[];
  20. static UBYTE far instrcode[] = { 0x0a,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  21.                 0x09,0x20,0x35,0x33,0x22,0x12,0x23,0x24,0x25,
  22.                 0x17,0x26,0x27,0x28,0x37,0x36,0x18,0x19,0x10,
  23.                 0x13,0x21,0x14,0x16,0x34 };
  24. static UBYTE far fastnotenum = 0;
  25. static BYTE far kbnotes[] = {
  26.     -1,-1,13,15,-1,18,20,22,-1,25,27,-1,30,32,-1,-1,
  27.     12,14,16,17,19,21,23,24,26,28,29,31,-1,-1,-1,-1,
  28.     -1,1,3,-1,6,8,10,-1,13,15,-1,-1,-1,-1,-1,-1,
  29.     -1,0,2,4,5,7,9,11,12,14,16 }; /* end = 0x3a */
  30. static UBYTE far fastnotes[10][3];
  31. UBYTE far nappkoodi[]={ 0x31,0x21,0x32,0x22,0x33,0x34,0x24,0x35,0x25,0x36,0x26,
  32.             0x37,
  33.             0x10,0x02,0x11,0x03,0x12,0x13,0x05,0x14,0x06,0x15,0x07,
  34.             0x16 };
  35. static UWORD chip zerodata = 0;
  36. UWORD far nappokt = 0,editline,*zeroptr = &zerodata;
  37. static UBYTE far lfx0,far lfx1,far rfx0,far rfx1;
  38. struct MEDSoftIntCmd komento;
  39. extern UWORD nykyinenosio;
  40.  
  41. static void PlayNote(UBYTE notenum,UWORD instr)
  42. {
  43.     komento.msic_data = (ULONG)notenum;
  44.     komento.msic_soitin = instr;
  45.     komento.msic_aani = currtrk;
  46.     komento.msic_cmd = SOITANUOTTI;
  47.     SetICR(ciaaresource,CIAICRF_SETCLR|CIAICRF_TA);
  48. }
  49.     
  50. static void UpdateScreen()
  51. {
  52.     if(soittotila == ALASOITA && (gadget6[25].GadgetID & 0x1000))
  53.         soittorivi++;
  54.     if(soittorivi > 63) { soittorivi = 0; PaivitaNaytto(TRUE); }
  55.     else PaivitaNaytto(1234); /* secret code */
  56. }
  57.     
  58. static UBYTE *CalcOffs(block,line,track)
  59. UWORD block,line,track;
  60. {
  61.     if(block > lohkoja - 1) return(0);
  62.     if(track > lohko[block]->numtracks - 1) return(0);
  63.     return(&lohko[block]->music[line * lohko[block]->numtracks * 3 +
  64.         3 * track]);
  65. }
  66.  
  67. static void PutNote(block,line,track,note,instr)
  68. UWORD block,line,track;
  69. UBYTE note;
  70. UWORD instr;
  71. {
  72.     UBYTE *putptr = CalcOffs(block,line,track);
  73.     if(!putptr) return;
  74.     *putptr = note;
  75.     if(instr > 0xF) *putptr |= 0x80;
  76.     *(putptr+1) = (*(putptr + 1) & 0x0F) | (instr << 4);
  77. }
  78.  
  79. static void PutData(block,line,track,num,val)
  80. UWORD block,line,track;
  81. UBYTE num,val;
  82. {
  83.     UBYTE *putptr = CalcOffs(block,line,track);
  84.     if(!putptr) return;
  85.     switch(num) {
  86.         case 0:
  87.         *(putptr+1) = (*(putptr + 1) & 0x0F) | (val << 4);
  88.         if(val > 0xF) *putptr |= 0x80; else *putptr &= ~0x80;
  89.         break;
  90.         case 1:
  91.             *(putptr+1) = (*(putptr + 1) & 0xF0) | val;
  92.         break;
  93.         case 2:
  94.             *(putptr+2) = (*(putptr + 2) & 0x0F) | (val << 4);
  95.         break;
  96.         case 3:
  97.             *(putptr+2) = (*(putptr + 2) & 0xF0) | val;
  98.         break;
  99.     }
  100. }
  101.  
  102. void SoitaNappain(UWORD code,BOOL canberecursive,UWORD qual)
  103. {
  104.     UBYTE notenum = 0,whichnum,keycount,callagain = FALSE,*thisnote;
  105.     UWORD edblock = soittolohko; /* soittolohko is volatile!! */
  106.     BYTE num = -1;
  107.     static UBYTE extraoffs[4] = { 8,17,26,35 };
  108.     editline = soittorivi;
  109.     if(code <= 0x3a && kbnotes[code] != -1)
  110.         notenum =  nappokt * 12 + kbnotes[code] + 1;
  111.     if(notenum > 63) return;
  112.     if(gadget6[0].GadgetID & 0x1000) {
  113.         if(kursorix == 4||kursorix == 13||kursorix == 22||
  114.             kursorix == 31) {
  115.             callagain = TRUE;
  116.             if(notenum) PutNote(edblock,editline,
  117.                 currtrk,notenum,soittimennum);
  118.             else if(code == 0x46) PutNote(edblock,editline,
  119.                 currtrk,0,0); /* DEL */
  120.             else callagain = FALSE;
  121.             if(callagain && (qual & (ALTLEFT|ALTRIGHT))) {
  122.                 thisnote = CalcOffs(edblock,editline,currtrk);
  123.                 if(thisnote) {
  124.                     *(thisnote+1) &= 0xf0;
  125.                     if(qual & ALTLEFT) {
  126.                         *(thisnote+1) |= lfx0;
  127.                         *(thisnote+2) = lfx1;
  128.                     } else {
  129.                         *(thisnote+1) |= rfx0;
  130.                         *(thisnote+2) = rfx1;
  131.                     }
  132.                 }
  133.             }
  134.         } else {
  135.         whichnum = kursorix - extraoffs[currpos];
  136.         for(keycount = 0; keycount < 32; keycount++)
  137.             if(code == instrcode[keycount]) { num = keycount; break; }
  138.         if(code == 0x46) num = 0;
  139.         if(num > 0xF && whichnum) num = -1; /* G-V only in # 1 */
  140.         if(num != -1) PutData(edblock,editline,currtrk,
  141.             whichnum,num);
  142.         }
  143.         if(notenum || num != -1 || code == 0x46) UpdateScreen();
  144.     }
  145.     if(notenum && num == -1) PlayNote(notenum,soittimennum);
  146.     if((gadget6[1].GadgetID & 0x1000) && callagain && canberecursive)
  147.         SoitaNappain(0x46,FALSE,qual); /* DEL, can't be recursive */
  148. }
  149.  
  150. void PutMNote(UBYTE note)
  151. {
  152.     editline = soittorivi;
  153.     if(note < 24 || note > 86) return;
  154.     note -= 23;
  155.     if(gadget6[0].GadgetID & 0x1000) {
  156.         PutNote(soittolohko,editline,currtrk,note,soittimennum);
  157.         UpdateScreen();
  158.     }
  159.     if(!tamakappale.midikanava[soittimennum]) PlayNote(note,soittimennum);
  160.     if(gadget6[1].GadgetID & 0x1000) SoitaNappain(0x46,FALSE,0);
  161. }
  162.  
  163. void DispFNnum()
  164. {
  165.     UBYTE fndisp;
  166.     if(nykyinenosio == 6) {
  167.         SetAPen(wrp,0);
  168.         Move(wrp,19,46);
  169.         fndisp = fastnotenum + '0';
  170.         Text(wrp,&fndisp,1);
  171.     }
  172. }
  173.  
  174. static void GetFNote(UBYTE nbr)
  175. {
  176.     UBYTE *thisnote = CalcOffs(soittolohko,editline = soittorivi,currtrk);
  177.     if(!thisnote) return; /* shouldn't happen */
  178.     fastnotes[nbr][0] = *thisnote;
  179.     fastnotes[nbr][1] = *(thisnote + 1);
  180.     fastnotes[nbr][2] = *(thisnote + 2);
  181. }
  182.  
  183. void EditHandler(gid)    /* this is a local gadget-handler */
  184. UWORD gid;
  185. {
  186.     UBYTE *thisnote = CalcOffs(soittolohko,editline = soittorivi,currtrk);
  187.     if(gid == 0x617 && fastnotenum) { fastnotenum--; DispFNnum(); }
  188.     else if(gid == 0x618 && fastnotenum < 9) { fastnotenum++; DispFNnum(); }
  189.     else if(gid == 0x61C && thisnote) GetFNote(fastnotenum);
  190.     else if(gid >= 0x01 && gid <= 0x0A && thisnote) { /* Shift + 0-9 */
  191.         if(gid == 0x0A) gid = 0;
  192.         if(gadget6[0].GadgetID & 0x1000) {
  193.             *thisnote = fastnotes[gid][0];
  194.             *(thisnote + 1) = fastnotes[gid][1];
  195.             *(thisnote + 2) = fastnotes[gid][2];
  196.             UpdateScreen();
  197.             if(gadget6[1].GadgetID & 0x1000)
  198.                 SoitaNappain(0x46,FALSE,0);
  199.         }
  200.         if(fastnotes[gid][0] & 0x7f) PlayNote((UBYTE)(fastnotes
  201.             [gid][0] & 0x7f),(UWORD)((fastnotes[gid][1] >> 4) +
  202.             (fastnotes[gid][0] & 0x80 ? 16 : 0)));
  203.     }
  204.     else if(gid == 0x61A && thisnote) {
  205.         lfx0 = *(thisnote+1) & 0x0f; lfx1 = *(thisnote+2); }
  206.     else if(gid == 0x61B && thisnote) {
  207.         rfx0 = *(thisnote+1) & 0x0f; rfx1 = *(thisnote+2); }
  208.     else if(gid >= 0x101 && gid <= 0x10A)
  209.         GetFNote((UBYTE)(gid == 0x10A ? 0 : gid - 0x100));
  210.     else if(gid == 0x46 && gadget6[0].GadgetID & 0x1000) {
  211.         *thisnote = *(thisnote + 1) = *(thisnote + 2) = 0;
  212.         UpdateScreen();
  213.         if(gadget6[1].GadgetID & 0x1000) SoitaNappain(0x46,FALSE,0);
  214.     }
  215. }
  216.